package com.example.yls.demoa;

import android.content.Context;
import android.database.DatabaseErrorHandler;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Created by yls on 2018/11/26.
 */

public class StudbOpenHelper extends SQLiteOpenHelper {
    public StudbOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }



    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
               String sql = "create table student(stuno varchar(20), name varchar(20),age int)";
               sqLiteDatabase.execSQL(sql);
    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVersion) {
          if(oldVersion == 1 && newVersion == 2){
              String sql = "alter table student add column phone varchar(20)";
              sqLiteDatabase.execSQL(sql);
          }
        if(oldVersion == 2 && newVersion == 3){
            String sql = "create table sore (stuno varchar(20),sore int)";
            sqLiteDatabase.execSQL(sql);
        }

    }
}
